// 模拟异步操作
let timeOut = (time) => new Promise(resolve => setTimeout(() => resolve('我取到数据啦!'), time));
// 等待总时长是 3 步之和
let parallel = async () => {
    await timeOut(5000).then(function (data) {console.log(data)}).catch(function (error){console.log(error)});
    await timeOut(15000).then(function (data) {console.log(data)}).catch(function (error){console.log(error)});
    await timeOut(8000).then(function (data) {console.log(data)}).catch(function (error){console.log(error)});
};
parallel(); // <Promise>
// 等待总时长是 3 步之中最长的那一步
let concurrent = async () => {
    let step1 = timeOut(5000).then(function (data) {console.log(data)}).catch(function (error){console.log(error)});
    let step2 = timeOut(15000).then(function (data) {console.log(data)}).catch(function (error){console.log(error)});
    let step3 = timeOut(8000).then(function (data) {console.log(data)}).catch(function (error){console.log(error)});
    await step1;
    await step2;
    await step3;
};
// concurrent(); // <Promise>

// async 函数不阻碍主线程执行
// async 函数默认返回是promise对象
// await 关键字必须出现在async函数中
// await 只等待promise